//
//  PlaceView.m
//  Park
//
//  Created by 123456 on 2017/11/20.
//  Copyright © 2017年 YTYangK. All rights reserved.
//

#import "PlaceView.h"
#define SCREEN_WIDTH  ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
@implementation PlaceView
{
    
}


- (void)awakeFromNib {
    [super awakeFromNib];

    self.PlaceArray  = [NSMutableArray arrayWithArray:@[@"志美园区",@"虹达路3号J-Park停车场",@"南屏科技园飞马",@"永顺冰室",@"拱北酒吧街",@"华发世纪城164",@"华发世纪城星巴克",@"华发商都C馆",@"拱北口岸",@"珠海机场",@"九州港客运码头",@"城轨珠海站"]];
    self.PlacePickerView.delegate = self;
    self.PlacePickerView.dataSource = self;
    self.PlacePickerView.backgroundColor = RGB(26, 32, 40, 1);
    self.PlacePickerView.alpha = 0.9;
    self.alpha = 0.9;

    self.backgroundColor = RGB(26, 32, 40, 1);
        NSInteger row=[self.PlacePickerView selectedRowInComponent:0];
        self.placeString=[self.PlaceArray objectAtIndex:row];
    
    NSLog(@"%@", self.placeString);
    

}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView*)pickerView
{
    return 1;
}

// 返回多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return self.PlaceArray.count;
    
}



// 返回每行的标题
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return self.PlaceArray[row];
}


-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSLog(@"%@",self.PlaceArray[row]);
    
    NSDictionary *dict = @{@"place":self.PlaceArray[row]};

    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"place" object:nil userInfo:dict];
    
}


- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 40;
    
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UILabel* pickerLabel = (UILabel*)view;
    if (!pickerLabel){
        pickerLabel = [[UILabel alloc] init];
        // Setup label properties - frame, font, colors etc
        //adjustsFontSizeToFitWidth property to YES
        pickerLabel.adjustsFontSizeToFitWidth = YES;
        [pickerLabel setTextAlignment:UITextAlignmentCenter];
        [pickerLabel setTextColor:[UIColor whiteColor]];
        [pickerLabel setFont:[UIFont boldSystemFontOfSize:17]];
    }
    // Fill the label text here
    pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
    return pickerLabel;
}



- (IBAction)Determine:(UIButton *)sender {
    [UIView animateWithDuration:0.5 animations:^{
        self.frame =CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 170);
        
    }completion:^(BOOL finished) {
        
        
    }];
    
}

-(NSMutableArray *)PlaceArray
{
    if (_PlaceArray == nil) {
        _PlaceArray = [[NSMutableArray alloc]init];
    }
    return _PlaceArray;
}



@end
